<template>
	<!-- 
	swiper中的transfrom会使fixed失效,此时用height="100%"固定高度; 
	swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
	-->
	<!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
	<mescroll-uni ref="mescrollRef" height="100%" @init="mescrollInit" bottom="180" :down="downOption"
		@down="downCallback" :up="upOption" @up="upCallback">
		<!-- 数据列表 -->
		<view class="item-wrapper" v-for="(item,indexs) in list" :key="indexs" @click="goDetail(item)">
			<view class="user-info">
				<!-- <uni-icons type="contact" class="icon" size="26" color="#222"></uni-icons> -->
				<view class="name">
					{{ item.supplierName }}
				</view>
				<uni-icons type="phone" v-if="item.serviceTel" size="18" color="#666"></uni-icons>
				<view class="tel" @click.stop="callPhone(item.serviceTel)">
					{{ item.serviceTel }}
				</view>
			</view>
			<view class="region">
				{{ item.businessAddress }}
			</view>
			<view class="info-wrapper">
				<view class="item">
					{{ index == 0 ? '待上报':'待审核' }} ：{{ item.waitDealCount }}个商品
				</view>
				<uni-icons type="right" color="#898989" size="18"></uni-icons>
			</view>
			<view class="btn-wrapper" v-if="index == '0'" @click.stop="remind(item)">
				<view class="btn">
					提醒上报
				</view>
			</view>
			<!-- <quotationItem :source="item" :index="index" @select="select"></quotationItem> -->
		</view>
		<!-- <uni-load-more v-if="list.length>1" :status="status" color="#1EAF22" :icon-size="16" style="margin-bottom: 20upx;" :content-text="contentText" /> -->
		<!-- <view class="nodata-wrapper" v-if="!list.length">
			<view class="loading-wrapper loading-image" style="position: relative;display: inline-block;" v-if="isLoading">
				<zero-loading  type="love"  position="absolute"></zero-loading>
			</view>
			<image v-else src="../../../../static/image/noorder.png" class="nodata-image" mode="widthFix"></image>
			<view class="text">
				 {{isLoading?'数据加载中...':'暂无订单'}}
			</view>
		</view> -->
	</mescroll-uni>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	import quotationItem from '@/subPage_quotation/quotationItem.vue'

	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				downOption: {
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					auto: false, // 不自动加载
					textNoMore: '没有更多啦~',
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						fixed: true,
						top: '200upx',
						tip: '~ 空空如也 ~', // 提示
						icon: 'https://sm.hobon.cc/static/hobon_noorder.png'
					}
				},
				isLoading: true,
				//mescroll:'',
				list: [],
				pageNum: 1,
				pageSize: 10,
				//org: this.$store.state.userInfo.orgRelation.org,
			}
		},
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			keywords: {
				type: String,
				default () {
					return ''
				}
			}
		},
		methods: {
			refresh() {
				this.mescroll.scrollTo(0, 0)
				this.$nextTick(() => {
					this.mescroll.resetUpScroll()
				})
			},
			refreshData(data) { //局部刷新数据

			},
			// mescrollInit(mescroll) {
			// 	this.mescroll = mescroll;
			// },
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
				this.$emit('getCount')
			},
			getData() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			async upCallback(page) {
				this.pageNum = page.num;
				const params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					supplierName: this.keywords,
					orders: [{
						"asc": false,
						"column": "id"
					}],
				};
				// if (status[this.index] !== '') {
				// 	params.orderStatusList = status[this.index];
				// }
				let url = "/adm/product/waitReportSupplierList"
				if (this.index === 1) {
					url = "/adm/product/waitAuditSupplierList"
				}
				const data = await this.$api.post(url, params, false)
				if (data.code === 200) {
					this.isLoading = false;
					if (this.pageNum === 1) {
						this.list = [];
					}
					data.data.records.forEach(item => {
						item.selected = false;
					})
					this.list = this.list.concat(data.data.records);
					console.log(this.list)
					this.mescroll.endBySize(data.data.records.length, data.data.total);
				} else {
					this.mescroll.endErr();
				}
			},
			select(id) {
				const array = this.list.filter(item => {
					if (item.id === id) {
						item.selected = !item.selected;
					}
					return item.selected
				})
				this.$emit("select", array)
			},
			callPhone(tel) {
				uni.makePhoneCall({
					phoneNumber: tel
				})
			},
			goDetail(item) {
				item.index = this.index;
				uni.navigateTo({
					url: '/subPage_quotation/detail?params=' + JSON.stringify(item)
				})
			},
			async remind(item) {
				if (!item.serviceTel) {
					uni.showToast({
						title: '暂未设置电话'
					})
					return
				}
				this.$showModal({
					title: '提示',
					content: '是否要提醒供应商上报价格？',
					confirmText: '确定',
					cancelText: '取消',
					success: async (res) => {
						if (res.confirm) {
							const data = await this.$api.post('/adm/pricesupply/quotation-reminder', {
								reminderInfos: [{
									"mobile": item.serviceTel,
									"quantity": item.waitDealCount
								}]
							}, false)
							if (data.code === 200) {
								uni.showToast({
									title: '已提醒'
								})
							}
						}
					}
				})
			}
		},
		components: {
			quotationItem
		}
	}
</script>
<style lang="scss" scope>
	.item-wrapper {
		margin: 0 20upx;
		border-radius: 20upx;
		background-color: #ffffff;
		margin-top: 20upx;
		overflow: hidden;

		.user-info {
			display: flex;
			align-items: center;
			font-size: 32upx;
			padding: 20upx 20upx 0 20upx;

			.name {
				font-weight: bold;
				flex: 1;
				color: #222222;
				font-size: 34upx;
			}

			.tel {
				color: #666;
			}

			.icon {
				margin-right: 5upx;
			}
		}

		.region {
			padding: 0 20upx;
			color: #888888;
			margin-top: 10upx;
		}

		.info-wrapper {
			display: flex;
			align-items: center;
			margin: 20upx 20upx;
			border-top: 1upx dashed #e1e1e1;
			border-bottom: 1upx dashed #e1e1e1;
			padding: 20upx 0;

			.item {
				flex: 1;
				color: #f90;
				font-weight: bold;
			}
		}

		.btn-wrapper {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			margin-bottom: 20rpx;
			margin-right: 20rpx;

			.date {
				font-size: 32upx;
				color: #666;
			}

			.btn {
				padding: 14upx 30upx;
				background-color: #ffffff;
				border: 1upx solid #bababa;
				border-radius: 10upx;
				font-size: 28upx;
				margin-left: 15upx;

				&.primary {
					color: #ffffff;
					background-color: #555BFF;
					border-color: #555BFF;
				}

				&.disabled {
					color: #ffffff;
					background-color: #aaaaaa;
					border-color: #aaaaaa;
				}
			}
		}

	}

	.nodata-wrapper {
		text-align: center;
		font-size: 32upx;
		color: #666666;

		.nodata-image {
			margin-top: 300upx;
			margin-bottom: 10upx;
			width: 246upx;
		}

		.loading-image {
			margin-top: 300upx;
			margin-bottom: 10upx;
			width: 296upx;
			height: 205upx;
		}
	}
</style>